PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

The Parent Property and the Current Application

The current application is either the default target application or whatever application is currently set as a script's parent property. The default parent property for any script that doesn't explicitly declare one is the default target application--usually, the application that is running the script, such as the Script Editor. You can use the predefined variable current application to refer to the current application.

You can make any application the current application for a script or script object simply by declaring it as a parent property. Any subsequent command in the script for which the script doesn't have a handler is passed to the application you declare as the parent, and subsequent occurrences of the constant current application refer to that application.

For example, this script declares the Finder as its parent property, then sends commands that close the Finder's frontmost window and return the application's name:

property parent: application "Finder"
close front window
tell current application to return my name --result: "Finder"

In this case, my refers to the current application (Finder). The Tell statement is optional; using return the name of me would produce the same result, because AppleScript sends the command to the Finder. If you remove the property declaration from the script, the Script Editor becomes the current application. When sent to the Script Editor, the Close command and the Return statement produce errors because the Script Editor doesn't understand them.

In the next example, the script Gertrude declares the Finder as its parent property and includes a handler that modifies the behavior of the scripting addition command Display Dialog.

script Gertrude
    property parent : application "Finder"
    on display dialog x
        tell application "Script Editor" to display dialog ¬
            "Finder has something to say"
        continue display dialog x
    end display dialog
end script

tell Gertrude to display dialog "Hello"

Because the script object Gertrude declares the Finder as its parent property, the on display dialog handler must use a Tell statement to send a separate Display Dialog command to the Script Editor. The handler then uses a Continue statement to pass the original Display Dialog command to the Finder, which becomes the frontmost application and uses the Display Dialog scripting addition to display "Hello".


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)